from __future__ import division
from math import *
from numpy import *
from Lists import Sat_M, Sat_Rad, Sat_r, Sat_v, m, sigma, rhill
from Constants import G

#Restart simulation in case stopped.  Take last result file and convert disk information into a Disk.txt file and a Satellites.txt file.
def f(switch1, M, switch2):

    #If switch1 = 0 there is no disk info.
    if switch1 == 0:
        pass
    else:
        w, x, y, z = loadtxt('Disk.txt', delimiter=',', usecols=range(4), unpack = True)

        for i in range(len(m)):
            m[i] = y[i]
            sigma[i] = z[i]

        #Switch2=0 if there is only one satellite.
        if switch2 == 0:
            a, b, c, d = loadtxt('Satellites.txt', delimiter=',', usecols=range(4), unpack = True)

            j = int(a)
            Sat_M[j] = b
            Sat_r[j] = c
            Sat_Rad[j] = d
            rhill[j] = Sat_r[j]*(Sat_M[j]/(M*3.))**(1./3.)
            Sat_v[j] = sqrt(G*M/Sat_r[j])
        #switch 2 = 2 if there are no satellites
        elif switch2 == 2:
            pass
        #switch2=1 (or anything else) if there are multiple satellites
        else:
            a, b, c, d = loadtxt('Satellites.txt', delimiter=',', usecols=range(4), unpack = True)

            for i in range(len(a)):
                j = int(a[i])
                Sat_M[j] = b[i]
                Sat_r[j] = c[i]
                Sat_Rad[j] = d[i]
                rhill[j] = Sat_r[j]*(Sat_M[j]/(M*3.))**(1./3.)
                Sat_v[j] = sqrt(G*M/Sat_r[j])
